// JavaScript Document
var startPosX;
var startPosY;
var powerA;
var powerB;
var isend = false;
var cpage = 1;
function touchStart(a) {
    startPosX = a.touches[0].pageX;
    startPosY = a.touches[0].pageY
}
function touchMove(c,obj) {
    var e = $("#"+obj).css("margin-left").replace("px", "");
    var a = Math.abs(Math.ceil(parseInt(e) / 71)) + 5;
    if (Math.abs(c.touches[0].pageY - startPosY) < Math.abs(c.touches[0].pageX - startPosX)) {
        c.preventDefault()
    }
    var g = c.touches;
    var b = parseInt($("#"+obj).css("width").replace("px", ""));
    if (c.touches.length == 1) {
        if (g[0].pageX > startPosX) {
            var f = g[0].pageX - startPosX;
            var d = parseInt($("#"+obj).css("margin-left").replace("px", ""));
            $("#"+obj).css("margin-left", d + f + "px")
        } else {
            var f = g[0].pageX - startPosX;
            var d = parseInt($("#"+obj).css("margin-left").replace("px", ""));
            $("#"+obj).css("margin-left", d + f + "px")
        }
        startPosX = g[0].pageX
    }
    if (g.length > 0) {
        powerA = powerB;
        powerB = g[g.length - 1].pageX
    }
}
function touchEnd(c,obj) {
    var d = parseInt($("#"+obj).css("margin-left").replace("px", ""));
    var b = parseInt($("#"+obj).css("width").replace("px", ""));
    if (powerA && powerB && powerA > 0 && powerB > 0) {
        var a = Math.abs(powerA - powerB);
        if (a > 0) {
            $("#"+obj).animate({
                "margin-left": (powerA > powerB ? d - a: d + a) + "px"
            },
            200)
        }
    }
    if (d > 0) {
        setTimeout(function() {
            $("#"+obj).animate({
                "margin-left": "0px"
            },
            200)
        },
        200)
    }
    if (Math.abs(d) > (b - 320)) {
        setTimeout(function() {
            $("#"+obj).animate({
                "margin-left": -((b - 320 + 20)) + "px"
            },
            200)
        },
        200)
    }
    powerA = 0;
    powerB = 0
}
